package com.srd.phone.bean;

import android.text.TextUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class BarrioInfo implements Serializable {

    public int id;
    public String name;
    public List<BarrioInfo> list = new ArrayList<>();

    public static List<BarrioInfo> parser(String json) {
        if (TextUtils.isEmpty(json))
            return null;
        List<BarrioInfo> list = new ArrayList<>();
        try {
            JSONArray jsonArray = new JSONArray(json);
            for (int i = 0; i < jsonArray.length(); i++) {
                list.add(parserInfo(jsonArray.getString(i)));
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;
    }

    private static BarrioInfo parserInfo(String json) {
        BarrioInfo info = new BarrioInfo();
        try {
            JSONObject jsonObject = new JSONObject(json);
            info.id = jsonObject.optInt("i");
            info.name = jsonObject.optString("n");
            info.list = parser(jsonObject.optString("c"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return info;
    }

}
